﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using System.Text.RegularExpressions;
using Playlist_file_loader.Core;

namespace Playlist_file_loader
{
    class M3uSimpleParser : Parsing.IParser
    {
        //-------------------------------------------------------------------//
        //-------------------------member variables--------------------------//
        //-------------------------------------------------------------------//

        private Core.ObjectContainer m_FileList;

        //-------------------------------------------------------------------//
        //-------------------------function definitions----------------------//
        //-------------------------------------------------------------------//


        //-------------------------------------------------------------------//
        // Description: ...
        public M3uSimpleParser(Stream stream)
        {
            m_FileList = Parse(stream);
        }

        //-------------------------------------------------------------------//
        // Description: 
        private Core.ObjectContainer Parse(Stream stream)
        {
            Core.ObjectContainer m3uFileList = new Core.ObjectContainer();
            StreamReader streamReader = new StreamReader(stream);
            while ( false == streamReader.EndOfStream )
            {
                String strLine = streamReader.ReadLine();
                String strFileName = System.IO.Path.GetFileName(strLine);
                m3uFileList.Add(new File(strLine, strFileName ));
            }
            return m3uFileList;
        }

        //-------------------------------------------------------------------//
        // Description: ...
        public Core.ObjectContainer GetFileList()
        {
            return m_FileList;
        }
    }
}
